class AiPackEntity {
  String? tag;
  String? image;
  String? content;
  List<SaleRule>? saleRule;
  List<AiPackItem>? aiItem;

  AiPackEntity(
      {this.tag, this.image, this.content, this.saleRule, this.aiItem});

  AiPackEntity.fromJson(Map<String, dynamic> json) {
    tag = json['tag'];
    image = json['image'];
    content = json['content'];
    if (json['saleRule'] != null) {
      saleRule = <SaleRule>[];
      json['saleRule'].forEach((v) {
        saleRule!.add(new SaleRule.fromJson(v));
      });
    }
    if (json['detail'] != null) {
      aiItem = <AiPackItem>[];
      json['detail'].forEach((v) {
        aiItem!.add(new AiPackItem.fromJson(v));
      });
    }
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['tag'] = this.tag;
    data['image'] = this.image;
    data['content'] = this.content;
    if (this.saleRule != null) {
      data['saleRule'] = this.saleRule!.map((v) => v.toJson()).toList();
    }
    if (this.aiItem != null) {
      data['detail'] = this.aiItem!.map((v) => v.toJson()).toList();
    }
    return data;
  }
}

class SaleRule {
  int? minTotal;
  int? maxTotal;
  double? discount;

  SaleRule({this.minTotal, this.maxTotal, this.discount});

  SaleRule.fromJson(Map<String, dynamic> json) {
    minTotal = json['minTotal'];
    maxTotal = json['maxTotal'];
    discount = json['discount'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['minTotal'] = this.minTotal;
    data['maxTotal'] = this.maxTotal;
    data['discount'] = this.discount;
    return data;
  }
}

extension SaleMin on List<SaleRule>{
  int get min {
    int min = 99;
    forEach((element) {
      if((element.minTotal??99) < min){
        min = element.minTotal!;
      }
    });
    return min;
  }
}

class AiPackItem {
  int? type;
  String? logo;
  String? name;
  String? tag;
  int? days;
  int? priceId;
  int? priceOld;
  int? price;

  AiPackItem(
      {this.type,
        this.logo,
        this.name,
        this.tag,
        this.days,
        this.priceId,
        this.priceOld,
        this.price});

  AiPackItem.fromJson(Map<String, dynamic> json) {
    type = json['type'];
    logo = json['logo'];
    name = json['name'];
    tag = json['tag'];
    days = json['days'];
    priceId = json['priceId'];
    priceOld = json['priceOld'];
    price = json['price'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['type'] = this.type;
    data['logo'] = this.logo;
    data['name'] = this.name;
    data['tag'] = this.tag;
    data['days'] = this.days;
    data['priceId'] = this.priceId;
    data['priceOld'] = this.priceOld;
    data['price'] = this.price;
    return data;
  }
}